package org.example.lys.design.template.draw;

import org.example.lys.design.template.algorithm.IDrawAlgorithm;
import org.example.lys.design.template.algorithm.Strategy;
import org.springframework.core.annotation.AnnotationUtils;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author liyishan
 * @date 2023/5/29 10:03
 * @apiNote
 */

public class DrawConfig {

    @Resource
    private List<IDrawAlgorithm> algorithmList;

    protected static Map<Integer, IDrawAlgorithm> drawAlgorithmGroup = new ConcurrentHashMap<>();


    @PostConstruct
    public void init() {
        algorithmList.forEach(algorithm -> {
            Strategy strategy = AnnotationUtils.findAnnotation(algorithm.getClass(), Strategy.class);
            if (null != strategy) {
                drawAlgorithmGroup.put(strategy.strategyMode().getCode(), algorithm);
            }
        });
    }

}
